package com.almm.web.controller;


import com.alibaba.fastjson.JSONObject;
import com.almm.web.common.ResponseResult;
import com.almm.web.service.ExceptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/demo")
public class ExceptionController {

    private static final Logger log = LoggerFactory.getLogger(ExceptionController.class);
    @Autowired
    ExceptService exceptService;





    @PostMapping("/test")
    public JSONObject test(@RequestBody JSONObject jsonObject) throws InterruptedException {
        JSONObject result = new JSONObject();
        try{
            String name = jsonObject.getString("name");
            if("a".equals(name)){
                result.put("code", 0);
                result.put("msg", "success");
                result.put("data", name);
                return result;
            }else if("b".equals(name)){
                Thread.sleep(600000);
                result.put("code", 0);
                result.put("msg", "success");
                result.put("data", name);
                return result;
            }else {
                result.put("code", 1);
                result.put("msg", "fail");
                result.put("data", null);
                return result;
            }
        }catch (Exception exception){
            log.error("异常:{}",exception.getMessage(), exception);
            throw exception;
        }
    }

}
